package com.ymatou.app.api.testcase;

import org.apache.commons.lang.math.RandomUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.api.parameter.RegisterByMobileBean;
import com.ymatou.app.api.service.RegisterByMobileCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.sqlwapper.YmtValidationCodeWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 用户手机注册 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_RegisterByMobile {
	private static RegisterByMobileBean rgbmbean;
	private static RegisterByMobileCall rgbmcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户手机注册");
	}

	@Before
	public void caseUp() {
		rgbmbean = new RegisterByMobileBean();
		rgbmcall = new RegisterByMobileCall();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(rgbmcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RegisterByMobile_001() {
		Logger.start(true,"用户手机注册成功");
		try {
			UserCallService user = new UserCallService();
			// 发送验证码
			String Phone = UserCallService.sendRegisterValidateCode();
			String Code = new YmtValidationCodeWapper().getValidateCode(Phone);
			rgbmbean.setCode(Code);
			Logger.comment("Code:" + Code);
			rgbmbean.setPhone(Phone);
			Logger.comment("Phone:" + Phone);
			String UserName = "test" + TestDataManager.getChineseName() + RandomUtils.nextInt(5);
			Logger.comment("UserName:" + UserName);
			rgbmbean.setUserName(UserName);
			String Password = "123456";
			Logger.comment("Password:" + Password);
			rgbmbean.setPassword(Password);
			String UserLogo = "123456";
			Logger.comment("UserLogo:" + UserLogo);
			rgbmbean.setUserLogo("UserLogo");
			// 发送报文
			rgbmcall.setData(rgbmbean);
			rgbmcall.callService();
			/*
			 * Logger.debug(rgbmcall.getEntityString());
			 * Logger.debug(rgbmcall.getReturnData());
			 */
			Logger.comment("rgbmcall send:" + rgbmcall.getEntityString());
			Logger.comment("rgbmcall response:" + rgbmcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, rgbmcall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.SUCCESSMSG, rgbmcall.getMsg(), "验证Msg");
			Logger.verifyEquals(ECode.BCODE0, rgbmcall.getBCode(), "验证BCode");
			Logger.verifyNotNull(rgbmcall.getUserId(), "验证返回的UserId");
			Logger.verifyNotNull(rgbmcall.getAccessToken(), "验证返回的AccessToken");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}